﻿using System;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ImageProcessor.Shared;
using ImageProcessor.Shared.ImageExtensions;
using System.Drawing;
using ImageProcessor.Shared.ImageExtensions;
using Fourier;

namespace ImageProcessor.Mish
{
    class ImageCalc
    {
        Bitmap org;

        public int width 
        {
            get
            {
                return org.Width;
            }            
        }

        public int height
        {
            get
            {
                return org.Height;
            }            
        }

        public ImageCalc(Bitmap bm)
        {
            org = (Bitmap) bm.Clone();
        }

        public Bitmap VKF(Bitmap bmp)
        {
            FFT A = new FFT(org);
            FFT B = new FFT(bmp);
            COMPLEX[,] A_zv = new COMPLEX[width, height];
            A.ForwardFFT();
            B.ForwardFFT();
            A.FFTShift();
            B.FFTShift();
            for (int i = 0; i < width; i++)
                for (int j = 0; j < height; j++)
                {
                    A_zv[i, j].real = A.FFTShifted[i, j].real;
                    A_zv[i, j].imag = -A.FFTShifted[i, j].imag;
                }
            for (int i = 0; i < width; i++)
                for (int j = 0; j < height; j++)
                    A_zv[i, j] *= B.FFTShifted[i, j];
            A.InverseFFT(A_zv);
            return A.Displayimage();
        }

        public Bitmap AKF()
        {
            FFT A = new FFT(org);
            COMPLEX[,] A_zv = new COMPLEX[width, height];
            A.ForwardFFT();
            A.FFTShift();
            for (int i = 0; i < width; i++)
                for (int j = 0; j < height; j++)
                {
                    A_zv[i, j].real = A.FFTShifted[i, j].real;
                    A_zv[i, j].imag = -A.FFTShifted[i, j].imag;
                }
            for (int i = 0; i < width; i++)
                for (int j = 0; j < height; j++)
                    A_zv[i, j] *= A.FFTShifted[i, j];
            A.InverseFFT(A_zv);
            return A.Displayimage();
        }

        public FFT FFT()
        {
            var temp = new FFT(org);
            temp.ForwardFFT();
            temp.FFTShift();
            temp.FFTPlot(temp.FFTShifted);

            temp.InverseFFT();
            return temp;
        }

        public FFT IFT()
        {
            var temp = new FFT(org);
            temp.ForwardFFT();
            temp.FFTShift();
            temp.FFTPlot(temp.FFTShifted);

            temp.InverseFFT();

            return temp;
        }


    }
}